package com.xiaoran.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.xiaoran.springcloud.server.PaymentHystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_fallbackMethod")
public class OrderHystrixController {
    @Resource
    private PaymentHystrixService paymentHystrixService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentinfo_ok(@PathVariable("id") int id){
        String result=paymentHystrixService.paymentinfo_ok(id);
        return result;

    }

    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    /*@HystrixCommand(fallbackMethod = "paymentTimeOutBreak",commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value = "1500")
    })*/
    @HystrixCommand
    public String paymentinfo_timeout(@PathVariable("id") int id){
        String reslut=paymentHystrixService.paymentinfo_timeout(id);
        return reslut;
    }
    public String paymentTimeOutBreak(@PathVariable("id") int id){
        return "我是消费者80，当前支付繁忙请10秒钟后再试一下/(ㄒoㄒ)/~~";
    }

    public String payment_Global_fallbackMethod(){
        return "异常信息，请稍后重试";
    }

}
